using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace lights
{
    public class comp_quickmesh_elem : MonoBehaviour
    {
        [HideInInspector]
        public int _colorindex;


        public void SetColor(Color color)
        {
            var mat = new Material(Shader.Find("lights/polyshader_single"));
            mat.color = color;
            this.GetComponent<Renderer>().material = mat;

        }
        // Start is called before the first frame update
        void Start()
        {

        }

        // Update is called once per frame
        void Update()
        {

        }
        public void InitColor()
        {
            this.SetColor(this.GetRoot()._colors[this._colorindex]);
        }
        public comp_quickmesh GetRoot()
        {
            var p = this.transform.parent;
            while (p != null)
            {
                var rp = p.GetComponent<comp_quickmesh>();
                if (rp != null)
                    return rp;
                else
                {
                    p = p.parent;
                }
            }
            return null;
        }
    }
}